--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_kagiyama_hina = General:new(extension, "hy_kagiyama_hina", "ten_k", 4, 4, General.Female)
    local gather_misfortune = fk.CreateSkill {
        name = "gather_misfortune",
    }
    gather_misfortune:addEffect(fk.TargetConfirming, {
        anim_type = "defensive",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(gather_misfortune.name) and target ~= player and data.card and data.card.trueName == "slash" and table.contains(data:getAllTargets(), target) and
                not player:isKongcheng() and
                data.from ~= player and player:inMyAttackRange(target)
        end,
        on_cost = function(self, event, target, player)
            local room = player.room
            local cardId = room:askToCards(player, {
                min_num = 1,
                max_num = 1,
                skill_name = gather_misfortune.name,
                prompt = "gather_misfortune_prompt::" .. target.id
            })
            if type(cardId) == "number" then
                cardId = { cardId }
            end
            if #cardId > 0 then
                event:setCostData(self, cardId[1])
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            player:addToPile("gather_misfortune_misfortune", event:getCostData(self), true, gather_misfortune.name)
            local top_cardId = room:getNCards(1)[1]
            room:moveCards({
                ids = { top_cardId },
                toArea = Card.Processing,
                moveReason = fk.ReasonJustMove,
                skillName = gather_misfortune.name,
            })
            local choice = room:askToChoice(player, {
                choices = { "gather_misfortune_replace", "gather_misfortune_cancel" },
                skill_name = gather_misfortune.name,
                cancelable = false,
            })
            if choice == "gather_misfortune_replace" then
                room:obtainCard(player, top_cardId, true, fk.ReasonPrey)
                if data.from ~= nil then
                    room:doIndicate(data.from, { player.id })
                end
                data:cancelTarget(target)
                data:addTarget(player)
            else
                if data.from ~= nil then
                    room:obtainCard(data.from, top_cardId, true, fk.ReasonPrey)
                end
                data:cancelTarget(target)
            end
        end
    })
    local misfortune_body = fk.CreateSkill {
        name = "misfortune_body",
    }
    misfortune_body:addEffect(fk.Damaged, {
        anim_type = "masochism",
        can_trigger = function(self, event, target, player)
            return player:hasSkill(misfortune_body.name) and target == player and not player.dead
        end,
        on_cost = function(self, event, target, player)
            return player.room:askToSkillInvoke(player, {
                skill_name = misfortune_body.name,
                prompt = "misfortune_body_prompt"
            })
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local judge = {
                who = player,
                reason = misfortune_body.name,
                pattern = ".|2~9|spade"
            }
            room:judge(judge)
            if judge.card.suit == Card.Spade and judge.card.number >= 2 and judge.card.number <= 9 then
                room:recover({
                    who = player,
                    num = 1,
                    recoverBy = player,
                    skillName = misfortune_body.name,
                })
            else
                room:drawCards(player, data.damage, misfortune_body.name)
            end
        end,
    })
    misfortune_body:addEffect(fk.DetermineDamageInflicted, {
        anim_type = "drawcard",
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(misfortune_body.name) and player == target and data.from == nil and not player.dead
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:drawCards(player, data.damage, misfortune_body.name)
            data:preventDamage()
        end
    })
    local sorrow_fortune = fk.CreateSkill {
        name = "sorrow_fortune",
        tags = {
            Skill.Wake
        },
    }
    sorrow_fortune:addEffect(fk.EventPhaseStart, {
        can_trigger = function(self, event, target, player, data)
            return target == player and player:hasSkill(sorrow_fortune.name) and player:usedSkillTimes(sorrow_fortune.name, Player.HistoryGame) == 0 and player.phase == Player.Start
        end,
        can_wake = function(self, event, target, player, data)
            return #player:getPile("gather_misfortune_misfortune") >= 3
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:changeMaxHp(player, -1)
            if player:isWounded() then
                room:recover({
                    who = player,
                    num = 1,
                    skillName = sorrow_fortune.name
                })
            end
            room:handleAddLoseSkills(player, "disaster", nil, true, false)
        end,
    })
    local disaster = fk.CreateSkill {
        name = "disaster",
    }
    disaster:addEffect("active", {
        anim_type = "offensive",
        expand_pile = "gather_misfortune_misfortune",
        times = function(self, player)
            return 2 - player:usedSkillTimes(disaster.name, Player.HistoryPhase)
        end,
        can_use = function(self, player)
            return player:hasSkill(disaster.name) and player:usedSkillTimes(disaster.name, Player.HistoryPhase) < 2 and #player:getPile("gather_misfortune_misfortune") > 0
        end,
        card_num = 1,
        card_filter = function(self, player, to_select, selected)
            return #selected == 0 and player:getPileNameOfId(to_select) == "gather_misfortune_misfortune"
        end,
        target_num = 1,
        target_filter = function(self, to_select, selected, selected_cards, card)
            return #selected == 0
        end,
        prompt = function(self, selected, selected_cards)
            return "disaster_prompt"
        end,
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            local target = cardUseEvent.tos[1]
            local card = Fk:getCardById(cardUseEvent.cards[1])
            room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonGive, disaster.name, "gather_misfortune_misfortune", true)
            local type
            if card.type == Card.TypeBasic then
                type = "basic"
            elseif card.type == Card.TypeTrick then
                type = "trick"
            else
                type = "equip"
            end
            if player ~= target then
                local discard = room:askToDiscard(target, {
                    min_num = 1,
                    max_num = 1,
                    skill_name = disaster.name,
                    pattern = ".|.|.|.|.|^" .. type,
                    prompt = "disaster_discard_prompt:::" .. "non-" .. type
                })
                if #discard == 0 then
                    room:loseHp(target, 1, disaster.name)
                end
            end
        end
    })
    extension:loadSkillSkels { gather_misfortune, misfortune_body, sorrow_fortune, disaster }
    hy_kagiyama_hina:addSkill("gather_misfortune")
    hy_kagiyama_hina:addSkill("misfortune_body")
    hy_kagiyama_hina:addSkill("sorrow_fortune")
    hy_kagiyama_hina:addRelatedSkill("disaster")
    Fk:loadTranslationTable {
        ["hy_kagiyama_hina"] = "键山雏",
        ["#hy_kagiyama_hina"] = "以身为祭",
        ["illustrator:hy_kagiyama_hina"] = "Bondson",
        ["designer:hy_kagiyama_hina"] = "碧珞，黑曜人形",
        ["cv:hy_kagiyama_hina"] = "",

        ["gather_misfortune"] = "集厄",
        [":gather_misfortune"] = "你攻击范围内的角色成为【杀】的目标时，你可以将一张手牌置于武将牌上，称为“厄”。之后你展示牌堆顶的一张牌并选择：代替其成为【杀】的目标并获得展示的牌；或取消之并令【杀】的使用者获得展示的牌。",
        ["gather_misfortune_prompt"] = "集厄：你可以用一张手牌改变此【杀】对%dest的指定",
        ["gather_misfortune_replace"] = "代替其成为【杀】的目标",
        ["gather_misfortune_cancel"] = "取消【杀】的目标",
        ["gather_misfortune_misfortune"] = "厄",

        ["misfortune_body"] = "厄身",
        [":misfortune_body"] = "在你受到伤害后，你可以进行判定：若结果为♠2~9，你回复1点体力，否则你摸等量的牌。你受到无来源的伤害时，防止此伤害并改为摸等量的牌。",
        ["misfortune_body_prompt"] = "厄身：你可以进行判定，并根据判定结果回复体力或摸牌",

        ["sorrow_fortune"] = "悲运",
        [":sorrow_fortune"] = "觉醒技，准备阶段，若你的“厄”不小于3，你减少1点体力上限，回复1点体力并获得“<a href = ':disaster'>灾祸</a>”。",

        ["disaster"] = "灾祸",
        [":disaster"] = "出牌阶段限两次，你可以将一张“厄”交给一名角色，若不为你，其须弃置一张与此“厄”不同类型的手牌或失去1点体力。",
        ["disaster_prompt"] = "灾祸：将一张“厄”交给一名角色",
        ["disaster_discard_prompt"] = "灾祸：你须弃置一张%arg牌，或失去一点体力",
        ["non-basic"] = "非基本",
        ["non-trick"] = "非锦囊",
        ["non-equip"] = "非装备",
    }
end
